/*
 * Creator:     ML
 * CreatDate:   
 * descripts：门诊日志
 * */
import React from 'react';
import { Form, Row, Col, Input, Select, Button, DatePicker, Table, Icon, Card, message, TimePicker, Tooltip, Divider, Radio, Modal } from 'antd';
import moment from 'moment';
import ColumnAuthoritysModel from 'pages/columnAuthority/ColumnAuthoritysModel';
// import { handleExcel } from 'tools/handleExcel.js';
import { $http } from '../../containers/config/https';
import store from '../../store';
import './css/outpatitentDom.less';
import { dayFormat, Util } from 'tools/index';
import CommonPagination from 'components/pagination/index';
import CardTypeRead from 'components/cardType/index';
import RecordCompoent from '../nurse/MedicalRecord/RecordCompoent';
import ShowMedicalRecordModal from 'pages/workstation/component/ShowMedicalRecordModal';

const FormItem = Form.Item;
const Option = Select.Option;

const OutPaitentLog = Form.create()(
  class OutPaitentLog extends React.Component {
    constructor(props) {
      const userData = React.$getSessionData();
      const ipConfig = React.$getSessionData('ipConfig');
      super(props)
      this.state = {
        ipConfig,
        loading: false,
        visible: false,
        total: 0,//表格总数据
        outPatData: [],//查询出来的门诊日志数据
        values: {},//查询条件数据
        searchLoading: false,//查询请求
        exportLoading: false,//导出请求
        rowIds: '',//表格行选中 页面数据
        locID: sessionStorage.userData ? [JSON.parse(sessionStorage.userData).locID] : "",//科室Id
        localArr: [],//loc下拉框数据
        doctorArr: [],//医生数据
        initDocID: "",
        isTransitionStart: false, // 起始时间
        isTransitionStop: false, // 结束时间
        columns: [],//门诊日志表头
        widthTotal: 0,//宽
        starNoVisible: false,
        startNoMessage: "",
        locNoVisible: false,
        locNoMessage: "",
        size: "small",
        dN: sessionStorage.userData ? JSON.parse(sessionStorage.userData).userName : "",
        lN: sessionStorage.userData ? JSON.parse(sessionStorage.userData).locDesc : "",
        // doctorID: sessionStorage.userData ? [JSON.parse(sessionStorage.userData).userID] : "",
        docName: sessionStorage.userData ? JSON.parse(sessionStorage.userData).userName : "",
        locName: sessionStorage.userData ? JSON.parse(sessionStorage.userData).locDesc : "",
        dateFrom: moment().format('YYYY-MM-DD'),
        dateTo: moment().format('YYYY-MM-DD'),
        dateF: moment().format('YYYY-MM-DD'),
        dateT: moment().format('YYYY-MM-DD'),
        pageSize: 20,
        userData: userData,
        reAdmFlag: 'N',
        visibleCard: true,
        regTitle: [],
        regTitleID: undefined, // 挂号号型
        emrVisible: false,
        emrAdmID: ''
      }
      this.bindCardType = React.createRef();
      this.bindCardNu = React.createRef();
      this.bindCardButton = React.createRef();

      this.patchCardNu = React.createRef();
      this.patchCardButton = React.createRef();

      this.changeCardNu = React.createRef();
      this.changeCardButton = React.createRef();
    }

    componentDidMount() {
      // 初始化设置table的高度以及表体的高度
      document.querySelector('.ant-table-body').style.height = store.getState().tableHeight.y + 195 + 'px';
      this.getOptions()
      this.getDoctor()
      this.getMainTableColumns()
      this.loadDiseaseMessage()
      this.findData()
      this.getStatus()
      if (this.state.size == "small") {
        this.setState({
          pageSize: 20
        })
      } else {
        this.setState({
          pageSize: 50
        })
      }
    }

    onColumnRef = (ref) => {
      this.columnRef = ref;
    }

    loadDiseaseMessage() {
      var params = {
        params: [{
          hospID: this.state.userData.hospID,
        }]
      }
      $http.post('urlDeault', this, {
        code: "03050253",
        data: params,
        success: function (res) {
          if (res.errorCode == '0') {
            this.setState({
              disease: res.result.data,
            })
          }
        }
      });
    }

    // 获取主列表columns
    getMainTableColumns = () => {
      let data = {
        params: [{
          compontName: "OutPatientLog", // 门诊日志
          type: 'C', // 卡类型id
        }]
      }
      $http.post('urlS', this, {
        code: '01040073',
        data: data,
        success: function (res) {
          if (+res.errorCode === 0) {
            let arr = res.result && res.result.C.length > 0 ? JSON.parse(JSON.stringify(res.result.C)).map((item, index) => {
              JSON.parse(JSON.stringify(res.result.C))[index]["seqNo"] = ""
              if (item.display === 'Y') {
                JSON.parse(JSON.stringify(res.result.C))[index]["seqNo"] = index + 1
              }
              return {
                align: item.align,
                widthNum: parseInt(item.width),
                width: item.width,
                dataIndex: item.dataIndex,
                title: <div onDoubleClick={() => this.columnRef.onOpenModel()}>{item.title}</div>,
                display: item.display,
                key: item.seqNo,
                fixed: item.fixed == 'L' ? 'left' : (item.fixed == 'R' ? 'right' : undefined),
                render: (text, record) => {
                  // console.log("record", record)
                  if (item.code == "medicalRecord") {
                    return (
                      <span style={{ color: "rgb(24, 144, 255)", cursor: "pointer" }}>
                        <span onClick={(e) => this.handleMedicalRecord(e, record)}>{this.state.localeProvider &&
                          this.state.localeProvider.ConsultationHistoryMedicalRecord ? this.setMessage('ConsultationHistoryMedicalRecord', 'descripts') : "查看病历"}</span>
                      </span>
                    )
                  }
                  return text
                }
              }
            }) : '';
            // console.log("arr", arr)
            let filterArr = arr.filter(function (item) { return item.display === 'Y' });
            // let seqArr = {
            //   align: "center",
            //   widthNum: 50,
            //   width: "50px",
            //   code: "seqNo",
            //   // dataIndex: "admID",
            //   title: "序号",
            //   display: "Y",
            //   key: "seqNo",
            // }
            // filterArr.unshift(seqArr)
            this.setState({ columns: filterArr, widthTotal: res.totalWidth })
            // console.log("res.totalWidth",res.totalWidth)
          }
        }
      })
    }

    onConsumeSomeRef = (ref) => {
      this.childConsumeSome = ref
    }

    //查看病历
    handleMedicalRecord = (e, row) => {
      this.childConsumeSome.showModal(row)
    }

    //获取科室
    getOptions = () => {
      let data = {}
      data = {
        params: [{
          hospID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).hospID : "",
        }]
      }
      $http.post('urlS', this, {
        code: "03020046",
        data: data,
        success: function (res) {
          if (res.errorCode === '0') {
            this.setState({
              localArr: res.result.Data,
            })
          } else {
            message.error('查询失败：' + res.errorMessage);
          }
        }
      })
    }

    //获取就诊状态03050138
    getStatus = () => {
      let data = {}
      data = {
        params: [{
        }]
      }
      $http.post('urlS', this, {
        code: "03050138",
        data: data,
        success: function (res) {
          if (res.errorCode === '0') {
            let statusAll = res?.result || [];
            this.setState({
              statusAll,
              regTitle: res?.regTitle || [], // 挂号号型
            }, () => {
              statusAll && statusAll.length > 0 && this.props.form.setFieldsValue({
                status: res.result[0].id
              })
            })
          } else {
            message.error('查询失败：' + res.errorMessage);
          }
        }
      })
    }

    //获取坐诊医生
    getDoctor() {
      let data = {}, ids = ''
      var { locID } = this.state;
      if (!Util.isEmpty(locID)) {
        for (var i = 0; i < locID.length; i++) {
          ids = locID[i]
        }
      }
      data = {
        params: [{
          // hospID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).hospID:"", // 医院id
          // locID: ids ? ids : (sessionStorage.userData ? JSON.parse(sessionStorage.userData).locID : ""), // 科室id
          locID: locID
          // groupID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).groupID:"", // 角色id
          // depDoctorID: "", // 科室医生id
        }]
      }
      $http.post('urlS', this, {
        code: "03020058",
        data: data,
        success: function (res) {
          if (+res.errorCode === 0) {
            this.setState({
              doctorArr: res.Data
            }, () => {
              // res.Data && res.Data.map((item, i) => {
              //   if (sessionStorage.userData) {
              //     if (JSON.parse(sessionStorage.userData).userID == item.doctorID) {
              //       this.props.form.setFieldsValue({ doctorId: item.doctorID })
              //     }
              //   }

              // })
            })
          }
        }
      });
    }

    //导出查询到的所有数据
    getAllData = () => {
      let { values } = this.state;
      console.dir(values)
      let data = {}
      data = {
        params: [{
          locID: this.state.locID || "",//科室
          docID: !Util.isEmpty(this.state.doctorID) ? this.state.doctorID : "",//医生
          diag: this.state.diag,//诊断信息
          number: this.state.patInfo,//病人基本信息
          statusID: this.state.status,//就诊状态
          diseaseID: this.state.diseaseID,//病种
          channel: this.state.channel,//病种
          regTitleID: this.state.regTitleID,
          language: sessionStorage.userData ? JSON.parse(sessionStorage.userData).language : undefined,
          stDate: this.state.dateF ? moment(this.state.dateF).format('YYYY-MM-DD') : '',//开始日期
          endDate: this.state.dateT ? moment(this.state.dateT).format('YYYY-MM-DD') : '',//截止日期
          stTime: this.state.stTime || '',//开始时间
          endTime: this.state.endTime || '',//截止时间
          reAdmFlag: this.state.reAdmFlag || '',
        }],
        pagination: [{
          pageSize: 10000,
          currentPage: 1,
        }]
      }
      $http.post('urlS', this, {
        code: '03050053',
        data: data,
        success: function (res) {
          if (+res.errorCode === 0) {
            this.setState({
              allPatData: res.result.Data,
            })
          }
        },
      })
    }

    //导出门诊日志表格
    exportData = () => {
      this.setState({
        exportLoading: true,
      })
      const { columns, outPatData, values } = this.state
      // this.getAllData()
      let data = {}
      data = {
        params: [{
          locID: this.state.locID ? (Array.isArray(this.state.locID) ? this.state.locID : [this.state.locID]) : '',//科室
          docID: !Util.isEmpty(this.state.doctorID) ? this.state.doctorID : "",//医生
          diag: this.state.diag,//诊断信息
          number: this.state.patInfo,//病人基本信息
          statusID: this.state.status,//就诊状态
          diseaseID: this.state.diseaseID,//病种
          channel: this.state.channel,//病种
          regTitleID: this.state.regTitleID,
          language: sessionStorage.userData ? JSON.parse(sessionStorage.userData).language : undefined,
          stDate: this.state.dateF ? moment(this.state.dateF).format('YYYY-MM-DD') : '',//开始日期
          endDate: this.state.dateT ? moment(this.state.dateT).format('YYYY-MM-DD') : '',//截止日期
          stTime: this.state.stTime || '',//开始时间
          endTime: this.state.endTime || '',//截止时间
          reAdmFlag: this.state.reAdmFlag || '',
        }],
        pagination: [{
          pageSize: 100000,
          currentPage: 1,
        }]
      }
      $http.post('urlS', this, {
        code: '03050276',
        data: data,
        success: function (res) {
          if (res.errorCode == '0') {
            this.setState({
              allPatData: res.result.url,
              exportLoading: false,
            }, () => {
              columns && columns.map((item, index) => {
                if (item.title.props && item.title.props) {
                  columns[index].title = columns[index].title.props.children
                }
              })
              //请求
              setTimeout(() => {
                this.setState({
                  exportLoading: false,
                }, () => {
                  this.downloadFile();
                })
              }, 1000)
            })
          } else {
            // this.setState({
            //   exportLoading: false,
            // })
            this.handleAddToTaskbar();
          }
        },
        error: function () {
          // this.setState({
          //   exportLoading: false,
          // })
          this.handleAddToTaskbar();
        }
      })
    }

    downloadFile() {
      let windowHost = window.location && window.location.origin ? window.location.origin : (window.location && window.location.protocol ? (window.location.protocol + '//' + window.location.hostname) : "");
      try {
        var elemIF = document.createElement('iframe');
        elemIF.src = windowHost + this.state.allPatData;
        elemIF.style.display = 'none';
        document.body.appendChild(elemIF);
        // 防止下载两次
        setTimeout(function () {
          document.body.removeChild(elemIF)
        }, 1000);
      } catch (e) {
        console.log(e);
      }
    }

    // 是否添加到任务栏提醒
    handleAddToTaskbar = () => {
      Modal.confirm({
        title: '导出超时！是否添加到导出任务进行导出？',
        okText: '添加导出任务',
        cancelText: '稍后再试',
        onOk: this.addExportTask,
        onCancel: () => {
          this.setState({
            exportLoading: false
          })
        },
      });
    }

    // 导出失败时添加到导出任务进行导出
    addExportTask = async () => {
      let { userData, ipConfig, page, pageSize, cardType, patCardNo } = this.state;
      let data = {
        params: [{
          queryParams: {
            params: [{
              cardTypeID: cardType,
              cardNo: patCardNo,
              locID: this.state.locID ? (Array.isArray(this.state.locID) ? this.state.locID : [this.state.locID]) : '',//科室
              docID: !Util.isEmpty(this.state.doctorID) ? this.state.doctorID : '',//医生
              diag: this.state.diag,//诊断信息
              diseaseID: this.state.diseaseID,//病种
              channel: this.state.channel,
              regTitleID: this.state.regTitleID,
              number: this.state.patInfo,//病人基本信息
              statusID: this.state.status,//就诊状态
              language: userData?.language || '',
              stDate: this.state.dateF ? moment(this.state.dateF).format('YYYY-MM-DD') : '',//开始日期
              endDate: this.state.dateT ? moment(this.state.dateT).format('YYYY-MM-DD') : '',//截止日期
              stTime: this.state.stTime || '',//开始时间
              endTime: this.state.endTime || '',//截止时间
              reAdmFlag: this.state.reAdmFlag || '',
            }],
            pagination: [{
              pageSize: parseInt(pageSize),
              currentPage: parseInt(page),
            }],
            code: '03050053',
            session: [{
              userID: userData?.userID || '',
              locID: userData?.locID || '',
              groupID: userData?.groupID || '',
              hospID: userData?.hospID || '',
              sessionID: userData?.sessionID || '',
              hospCode: userData?.hospCode || '',
              language: userData?.language || '',
              hostName: ipConfig?.hostName || '',
              ipv4: ipConfig?.ipv4 || '',
              ipv6: ipConfig?.ipv6 || '',
              mac: ipConfig?.mac || ''
            }
            ],
          },
          queryCode: '03050053',
          componentCode: 'OutPatientLog'
        }],
        pagination: [{
          pageSize: parseInt(pageSize),
          currentPage: parseInt(page),
        }]
      };
      await this.sleep(1000); // 延时，按钮效果
      const resObj = await React.$asyncPost(this, '11020007', data);
      if (resObj) {
        let errorCode = resObj.errorCode;
        if (errorCode === '0') {
          let downLoadUrl = resObj.result.downloadURL;
          if (downLoadUrl === '') {
            this.exportNotification(); // 提示栏
            store.dispatch({
              type: 'downloadTask',
              value: {
                timeStamp: new Date().getTime(),
                startDate: moment(new Date()).format('YYYY-MM-DD'),
                endDate: moment(new Date()).format('YYYY-MM-DD'),
              }
            })
          } else { // 同步-直接取到链接后下载
            window.open(downLoadUrl, '_parent')
          }
          this.setState({
            exportLoading: false
          });
        } else {
          this.setState({
            exportLoading: false
          });
          message.error(resObj.errorMessage)
        }
      }
    }

    //延时执行
    sleep = (millisecond) => {
      return new Promise(resolve => {
        setTimeout(() => {
          resolve()
        }, millisecond)
      })
    };

    //右上角提示栏
    exportNotification = () => {
      const msgValue = (<p>数据正在导出，导出完成后可在右上角<span style={{ color: 'red' }}>↗</span><span style={{ fontWeight: 'bold' }}>【导出任务列表】</span>中下载</p>);
      notification.info({
        message: '导出中..',
        description: msgValue,
        placement: 'topRight',
        style: {
          top: 30,
        },
      });
    };

    // 修改page和pageSize 跳转至---
    onChange = (e) => {
      this.setState({ page: e, pageSize: this.state.pageSize }, () => {
        // 重新调用查询方法
        let { values } = this.state;
        this.getFindDate(values);
      })
    }

    //下拉选择页数
    onShowSizeChange = (page, pageSize) => {
      this.setState({ page: 1, pageSize: pageSize }, () => {
        // 重新调用查询方法
        let { values } = this.state;
        // if (this.state.outPatData && this.state.outPatData.length > 0) {
        this.getFindDate(values, "search");
        // }
      })
    }

    // 显示分页总条数
    showTotal(total) {
      return `共 ${total} 条`;
    }

    getValue = (cardType, patCardNo) => {
      this.setState({
        cardType,
        patCardNo,
      })
    }

    //获取查询数据
    getFindDate = (values, e) => {
      this.setState({
        searchLoading: true
      })
      console.dir(values)
      let { page, pageSize, dN, lN, dateF, dateT, cardType, patCardNo } = this.state;
      let data = {}
      data = {
        params: [{
          cardTypeID: cardType,
          cardNo: patCardNo,
          locID: this.state.locID ? (Array.isArray(this.state.locID) ? this.state.locID : [this.state.locID]) : '',//科室
          docID: !Util.isEmpty(this.state.doctorID) ? this.state.doctorID : "",//医生
          diag: this.state.diag,//诊断信息
          diseaseID: this.state.diseaseID,//病种
          channel: this.state.channel,
          regTitleID: this.state.regTitleID,
          number: this.state.patInfo,//病人基本信息
          statusID: this.state.status,//就诊状态
          language: sessionStorage.userData ? JSON.parse(sessionStorage.userData).language : undefined,
          stDate: this.state.dateF ? moment(this.state.dateF).format('YYYY-MM-DD') : '',//开始日期
          endDate: this.state.dateT ? moment(this.state.dateT).format('YYYY-MM-DD') : '',//截止日期
          stTime: this.state.stTime || '',//开始时间
          endTime: this.state.endTime || '',//截止时间
          reAdmFlag: this.state.reAdmFlag || '',
        }],
        pagination: [{
          pageSize: parseInt(pageSize),
          currentPage: parseInt(page),
        }]
      }
      $http.post('urlS', this, {
        code: '03050053',
        data: data,
        success: function (res) {
          if (+res.errorCode === 0) {
            this.setState({
              searchLoading: false,
              search: e
            })
            // this.removPat()
            this.setState({ docName: dN, locName: lN, dateFrom: dateF, dateTo: dateT, outPatData: res.result.Data && res.result.Data ? res.result.Data : [], total: res.result.TotalCount && res.result.TotalCount != undefined ? res.result.TotalCount : 0, }, () => {
            })
          } else {
            this.setState({
              searchLoading: false
            })
          }
        },
        error: function () {
          this.setState({
            searchLoading: false
          })
        }
      })
    }

    //点击查询---门诊日志列表
    findData = () => {
      this.props.form.validateFields((err, values) => {
        this.locTip()
        if ((values.dateFrom && values.dateFrom) && (values.dateTo && values.dateTo)) {
          if (moment(values.dateFrom).format('YYYYMMDD') > moment(values.dateTo).format('YYYYMMDD')) {
            this.setState({
              starNoVisible: true,
              startNoMessage: "开始日期大于结束日期",
            }, () => {
              setTimeout(() => {
                this.visibleTip()
              }, 1500)
            })
            return
          }
        }
        if (!err) {
          this.setState({
            values: values,
            rowIds: ""
          })
          this.setState({ page: 1, pageSize: this.state.pageSize }, () => {
            this.onShowSizeChange("1", this.state.pageSize)
            this.removPat()
          })
        }
      })
    }

    handleOk = (e) => {
      this.setState({ loading: true });
      setTimeout(() => {
        this.setState({ loading: false, visible: false });
      }, 3000);
    }

    //绑定弹窗
    showModal = () => {
      this.setState({
        visible: true,
      });
    }

    handleCancel = () => {
      this.handleRest()
      this.setState({
        visible: false,
        bindMoreInfo: false,
        bindVail: true
      });
    }

    //卡操作成功后----关闭弹窗
    closeCardPop = () => {

    }

    //点击查询后 表格行
    setRowClassNames = (record) => {
      return record.admID === this.state.rowIds ? 'clickRowStyle' : (record.hospFlag == 'Y' ? 'hospAdviceStyle' : '');
    }

    //设置patientData 
    setPat = (record) => {
      window.sessionStorage.setItem("patientData",
        JSON.stringify({
          admID: record.admID,
          patID: record.patID,
        }));
    }

    //移除patientData 
    removPat = () => {
      window.sessionStorage.removeItem("patientData");
    }

    //点击Row 
    onClickRow = (record) => {
      return {
        onClick: () => {
          this.setState({
            parms: record,
          })
          if (this.state.rowIds === "") {
            this.setState({
              rowIds: record.admID,
            });
            this.setPat(record)
          } else {
            if (this.state.rowIds !== record.admID) {
              this.setState({
                rowIds: record.admID,
              });
              //设置patientData 
              this.setPat(record)
            } else {
              this.setState({
                rowIds: "",
                detailInfo: {},
              });
              this.removPat()
            }
          }
        },
      };
    }

    //选择科室类型  清空医生 
    selectLocId = (data) => {
      this.props.form.setFieldsValue({ doctorId: undefined })
      if (!data) {
        this.setState({
          lN: "",
          dN: "",
          locID: "",
          doctorID: undefined
        }, () => {
          this.onShowSizeChange("1", this.state.pageSize)
        })
      } else {
        this.setState({
          locID: data,
          dN: "",
          doctorID: undefined
        }, () => {
          this.getDoctor()
        })
      }
    }

    //展开/关闭起始时间
    handleOnOpenChangeStart = (status) => {
      if (!status) {
        this.setState({ isTransitionStart: true })
      } else {
        this.setState({ isTransitionStart: false })
      }
    }

    //展开/关闭截止时间
    handleOnOpenChangeStop = (status) => {
      if (!status) {
        this.setState({ isTransitionStop: true })
      } else {
        this.setState({ isTransitionStop: false })
      }
    }

    //未填写科室
    locTip = () => {
      this.props.form.validateFields(['locaId',], (errors, values) => {
        if (!errors) {
          this.setState({
            locNoVisible: false
          })
        } else {
          this.setState({
            locNoVisible: true,
            locNoMessage: errors.locaId.errors[0].message,
          })
        }
      });
    }

    //隐藏提示信息
    visibleTip = () => {
      this.setState({
        starNoVisible: false,
        locNoVisible: false
      })
    }

    //选择医生 科室
    handleOp = (n, name, id) => {
      if (n == 1) {
        this.setState({
          dN: name,
          doctorID: id
        })
      } else {
        this.setState({
          lN: name
        })
      }
    }

    //清空医生
    clearDoctor = (v) => {
      if (!v) {
        this.setState({
          dN: "",
          doctorID: ""
        })
      }
    }

    onPanelChange(name, e) {
      this.setState({
        [name]: e ? moment(e).format(dayFormat) : ''
      })
    }

    handleChangeTIme(name, e) {
      this.setState({
        [name]: e ? moment(e).format('HH:mm') : ''
      })
    }

    handleChangeSelect(name, e) {
      this.setState({
        [name]: e
      })
    }

    handleChangeInput(name, e) {
      this.setState({
        [name]: e.target.value
      })
    }

    handleChangeRadio(name, e) {
      this.setState({
        [name]: e.target.value
      })
    }

    // 隐藏左侧card
    handleHideLeftCard = () => {
      this.setState({ visibleCard: false })
    }

    // 显示左侧card
    handleShowLeftCard = () => {
      this.setState({ visibleCard: true })
    }

    // 查看病历
    modifyEMRModal = (visible, record, e) => {
      React.$stopPropagation(e);
      if (visible && !(record && record.admID)) {
        message.error('就诊ID不存在，请稍后重试！');
        return;
      }
      this.setState({ emrVisible: visible, emrAdmID: record?.admID || '' });
    }

    render() {
      const { getFieldDecorator } = this.props.form;
      const { searchLoading, localArr, statusAll, doctorArr, exportLoading, widthTotal, columns, dateFrom, dateTo, regTitle, visibleCard, emrVisible, emrAdmID } = this.state;
      const mesIcon = <Icon type="exclamation-circle" />
      // let dateFrom = moment().format('YYYY-MM-DD')
      // let dateTo = moment().format('YYYY-MM-DD')
      //科室
      let localArrOp = []
      localArr && localArr.map(item => {
        localArrOp.push(<Option key={item.id} onClick={() => this.handleOp(2, item.descripts)} disabled={item.disabled} value={item.id} title={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
      })
      //就诊状态
      let statusOp = []
      statusAll && statusAll.map(item => {
        statusOp.push(<Option key={item.id} value={item.id} title={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
      })
      //医生
      let doctorArrOp = []
      doctorArr && doctorArr.map(item => {
        doctorArrOp.push(<Option key={item.doctorID} title={item.descripts + '^' + item.descriptsSPCode} value={item.doctorID}>{item.descripts}</Option>)
      })

      //病种
      let diseaseOption = []
      this.state.disease && this.state.disease.map((item, index) => {
        diseaseOption.push(<Option key={index} value={item.id}>{item.descripts}</Option>)
      })

      const operationObj = {
        width: 100,
        title: '操作',
        fixed: 'right',
        align: 'center',
        key: 'operation',
        render: (text, record) => (
          <div>
            <span className="span" onClick={(e) => this.modifyEMRModal(true, record, e)}>查看病历</span>
          </div>
        ),
      };

      return (
        <div style={{ padding: '4px 2px', width: '100%', height: '100%', background: '#F5F7FE' }} className="outPaitentDom">
          {!visibleCard ? (<Card
            className="show-card"
            style={{
              width: '20px', background: '#f5f4f4',
              float: "left",
              height: store.getState().tableHeight.y + 236 + 'px'
              , cursor: 'pointer', paddingTop: 200, textAlign: 'center'
            }} hoverable={true} onClick={this.handleShowLeftCard}>
            <div className='change-card-icon-show'><Tooltip title="显示查询条件">
              <Icon type='double-right' style={{ fontSize: '18px' }} /></Tooltip></div>
            显示查询条件
          </Card>) : (
            <Card style={{ height: store.getState().tableHeight.y + 236, width: '20%', float: 'left' }}>
              <Form>
                <Row style={{ margin: '0' }}>
                  <Col span={25}><CardTypeRead getValue={this.getValue} getQuery={this.findData} type={'update'}></CardTypeRead></Col>
                  <Col span={25}>
                    <FormItem label={''} >
                      {getFieldDecorator('patInfo', {
                        initialValue: undefined,
                        rules: [{ required: false, message: '' }]
                      })(

                        <Input.Group>
                          <Input className='express-input-disable' style={{ width: '30%', textAlign: 'center' }} value={'人员标识：'} disabled />
                          <Input
                            allowClear
                            onChange={this.handleChangeInput.bind(this, 'patInfo')}
                            placeholder='病人ID/姓名/身份证号码/手机号码'
                            onPressEnter={this.findData}
                            style={{ width: '69.9%' }}
                          />
                        </Input.Group>
                      )}
                    </FormItem>
                  </Col >
                  <Col span={25} className="locaIdDom">
                    <Tooltip getPopupContainer={() => document.querySelector('.locaIdDom')} overlayStyle={{ zIndex: 999, }} overlayClassName="toolTipDom locId" title={<div className="titleIcon">{mesIcon}<span >{this.state.locNoMessage}</span></div>} visible={this.state.locNoVisible}>
                      <FormItem >
                        {getFieldDecorator('locaId', {
                          initialValue: sessionStorage.userData ? JSON.parse(sessionStorage.userData).locID : undefined,
                          rules: [{ required: false, message: '' }],
                        })(
                          <Input.Group>
                            <Input className='express-input-disable' style={{ width: '30%', textAlign: 'center' }} value={'科室：'} disabled />
                            <Select mode="multiple"
                              showSearch className='express-select-border' style={{ width: '69.9%' }}
                              allowClear value={this.state.locID ? this.state.locID : undefined}
                              optionFilterProp="title"
                              placeholder='请选择科室'
                              onChange={this.selectLocId}
                              onFocus={this.visibleTip}
                            >
                              {localArrOp}
                            </Select>
                          </Input.Group>
                        )}
                      </FormItem>
                    </Tooltip>
                  </Col>
                  <Col span={25} style={{ paddingRight: "0" }}>
                    <FormItem>
                      {getFieldDecorator('doctorId', {
                        rules: [{ required: false, message: '' }]
                      })(
                        <Input.Group>
                          <Input className='express-input-disable' style={{ width: '30%', textAlign: 'center' }} value={'医生：'} disabled />
                          <Select
                            showSearch className='express-select-border' style={{ width: '69.9%' }}
                            allowClear value={this.state.doctorID} mode="multiple"
                            optionFilterProp="title"
                            placeholder='请先选择医生'
                            onChange={this.handleChangeSelect.bind(this, 'doctorID')}
                          >
                            {doctorArrOp}
                          </Select>
                        </Input.Group>
                      )}
                    </FormItem>
                  </Col >

                  <Col span={25} style={{ paddingRight: "0" }}>
                    <FormItem>
                      {getFieldDecorator('diseaseID', {
                        initialValue: undefined,
                        rules: [{ required: false, message: '' }]
                      })(
                        <Input.Group>
                          <Input className='express-input-disable' style={{ width: '30%', textAlign: 'center' }} value={'病种：'} disabled />
                          <Select
                            showSearch className='express-select-border' style={{ width: '69.9%' }}
                            allowClear mode="multiple"
                            optionFilterProp="title"
                            placeholder='请先选择病种'
                            onChange={this.handleChangeSelect.bind(this, 'diseaseID')}
                          >
                            {diseaseOption}
                          </Select>
                        </Input.Group>
                      )}
                    </FormItem>
                  </Col >

                  <Col span={25}>
                    <FormItem>
                      {getFieldDecorator('diag', {
                        initialValue: undefined,
                        rules: [{ required: false, message: '' }]
                      })(
                        <Input.Group>
                          <Input className='express-input-disable' style={{ width: '30%', textAlign: 'center' }} value={'诊断信息：'} disabled />
                          <Input
                            allowClear
                            placeholder='支持模糊搜素'
                            onChange={this.handleChangeInput.bind(this, 'diag')}
                            onPressEnter={this.findData}
                            style={{ width: '69.9%' }}
                          />
                        </Input.Group>
                      )}
                    </FormItem>
                  </Col >

                  <Col span={25}>
                    <FormItem>
                      {getFieldDecorator('channel', {
                        initialValue: undefined,
                        rules: [{ required: false, message: '' }]
                      })(
                        <Input.Group>
                          <Input className='express-input-disable' style={{ width: '30%', textAlign: 'center' }} value={'渠道：'} disabled />
                          <Input
                            allowClear
                            placeholder='请输入渠道'
                            onChange={this.handleChangeInput.bind(this, 'channel')}
                            style={{ width: '69.9%' }}
                          />
                        </Input.Group>
                      )}
                    </FormItem>
                  </Col >

                  <Col span={25} style={{ paddingLeft: "0" }}>
                    <FormItem >
                      {getFieldDecorator('status', {
                        initialValue: undefined,
                        rules: [{ required: false, message: '' }]
                      })(
                        <Input.Group>
                          <Input className='express-input-disable' style={{ width: '30%', textAlign: 'center' }} value={'就诊状态：'} disabled />
                          <Select onChange={this.handleChangeSelect.bind(this, 'status')}
                            showSearch className='express-select-border'
                            allowClear placeholder='请选择就诊状态'
                            optionFilterProp="title"
                            style={{ width: '69.9%' }}
                          >
                            {statusOp}
                          </Select>
                        </Input.Group>
                      )}
                    </FormItem>
                  </Col >
                  <Col span={25} style={{ paddingLeft: "0" }}>
                    <FormItem >
                      {getFieldDecorator('regTitleID', {
                        initialValue: undefined,
                        rules: [{ required: false, message: '' }]
                      })(
                        <Input.Group>
                          <Input className='express-input-disable' style={{ width: '30%', textAlign: 'center' }} value={'挂号号型：'} disabled />
                          <Select onChange={this.handleChangeSelect.bind(this, 'regTitleID')}
                            showSearch className='express-select-border'
                            allowClear placeholder='请选择'
                            optionFilterProp="title"
                            style={{ width: '69.9%' }}
                          >
                            {React.$SelectOptions(regTitle)}
                          </Select>
                        </Input.Group>
                      )}
                    </FormItem>
                  </Col >
                  <Col span={25} className="starDataDom" style={{ padding: "0" }}>
                    <Tooltip getPopupContainer={() => document.querySelector('.starDataDom')} overlayStyle={{ zIndex: 999, }} overlayClassName="toolTipDom starData" title={<div className="titleIcon">{mesIcon}<span >{this.state.startNoMessage}</span></div>} visible={this.state.starNoVisible}>
                      <FormItem >
                        {getFieldDecorator('dateFrom', {
                          initialValue: moment(),
                          rules: [{ required: false, message: '' }],
                        })(
                          <Input.Group>
                            <Input className='express-input-disable' style={{ width: '30%', textAlign: 'center' }} value={'开始日期：'} disabled />
                            <DatePicker onFocus={this.visibleTip} onChange={this.onPanelChange.bind(this, 'dateF')} style={{ width: '69.9%' }} placeholder={'开始日期'} disabledDate={(curDate) => {
                              return curDate && curDate > moment().endOf('day');
                            }} />
                          </Input.Group>
                        )}
                      </FormItem>
                    </Tooltip>
                  </Col>
                  <Col span={25} style={{ paddingLeft: "5px", paddingRight: "0px" }}>
                    <Form.Item>
                      <Col>
                        {getFieldDecorator('locStartTime', {
                          initialValue: undefined,
                        })(
                          <Input.Group>
                            <Input className='express-input-disable' style={{ width: '30%', textAlign: 'center' }} value={'开始时间：'} disabled />
                            <TimePicker style={{ width: '69.9%' }} separator=":" showToday onChange={this.handleChangeTIme.bind(this, 'stTime')}
                              format={this.state.isTransitionStart ? 'HH:mm' : 'HHmm'} onOpenChange={this.handleOnOpenChangeStart} placeholder="开始时间" />
                          </Input.Group>
                          // <TimePicker style={{ width: '100%' }} separator=":" showToday format={this.state.isTransitionStart ? 'HH:mm' : 'HHmm'} onOpenChange={this.handleOnOpenChangeStart} placeholder="接诊时间" />
                        )}
                      </Col>
                    </Form.Item>
                  </Col>
                  <Col span={25} style={{ padding: "0px" }}>
                    <FormItem>
                      {getFieldDecorator('dateTo', {
                        initialValue: moment(),
                        rules: [{ required: false, message: '' }],
                      })(
                        // <DatePicker style={{ width: '100%' }} onChange={(v) => this.onPanelChange(2, v)} placeholder={'挂号日期'} />
                        <Input.Group>
                          <Input className='express-input-disable' style={{ width: '30%', textAlign: 'center' }} value={'结束日期：'} disabled />
                          <DatePicker style={{ width: '69.9%' }} onChange={this.onPanelChange.bind(this, 'dateT')} placeholder={'结束日期'} />
                        </Input.Group>
                      )}
                    </FormItem>
                  </Col >
                  <Col span={25} >
                    <Form.Item>
                      {getFieldDecorator('locStopTime', {
                        initialValue: undefined,
                      })(
                        // <TimePicker separator=":" showToday format={this.state.isTransitionStop ? 'HH:mm' : 'HHmm'} onOpenChange={this.handleOnOpenChangeStop} style={{ width: '94%' }} placeholder="接诊时间" />
                        <Input.Group>
                          <Input className='express-input-disable' style={{ width: '30%', textAlign: 'center' }} value={'结束时间：'} disabled />
                          <TimePicker separator=":" showToday format={this.state.isTransitionStop ? 'HH:mm' : 'HHmm'} onChange={this.handleChangeTIme.bind(this, 'endTime')}
                            onOpenChange={this.handleOnOpenChangeStop} style={{ width: '69.9%' }} placeholder="结束时间" />
                        </Input.Group>
                      )}
                    </Form.Item>
                  </Col>

                  <Col span={25}>
                    <Radio.Group value={this.state.reAdmFlag} onChange={this.handleChangeRadio.bind(this, 'reAdmFlag')}>
                      <Radio value={''}>全部</Radio>
                      <Radio value={'N'}>初诊</Radio>
                      <Radio value={'Y'}>复诊</Radio>
                    </Radio.Group>
                  </Col>

                  <Col span={25} style={{ marginTop: 10 }}>
                    <Button
                      onClick={this.exportData}
                      loading={exportLoading} style={{ width: '48%' }}
                      disabled={this.state.outPatData && this.state.outPatData.length == 0}
                    >
                      导出
                    </Button>

                    <Button onClick={this.findData} loading={searchLoading} type="primary" style={{ width: '48%', marginLeft: 10 }}>查询</Button>
                  </Col>
                  {/* <Col span={1} style={{ textAlign: "center", padding: "0 0 0 24px" }}>
                    <FormItem  {...formItemLayout}>
                      {getFieldDecorator('export', {
                        initialValue: undefined,
                        rules: [{ required: false, message: '' }],
                      })(
                        <Button
                          onClick={this.exportData}
                          loading={exportLoading}
                          type="primary"
                          disabled={this.state.outPatData && this.state.outPatData.length == 0}
                        >
                          导出
                    </Button>
                      )}
                    </FormItem>
                  </Col>
                  <Col span={1} style={{ paddingLeft: "30px" }}>
                    <FormItem  {...formItemLayout}>
                      {getFieldDecorator('findData', {
                        initialValue: undefined,
                        rules: [{ required: false, message: '' }],
                      })(
                        <Button onClick={this.findData} loading={searchLoading} type="primary">查询</Button>
                      )}
                    </FormItem>
                  </Col> */}
                </Row>
              </Form>
            </Card>
          )}
          <Card style={{ float: 'right', width: !visibleCard ? "calc(100% - 20px)" : '79.5%' }}>
            <Table
              scroll={{ x: (columns && columns.length > 0 ? widthTotal : 1000), y: store.getState().tableHeight.y + 80 }}
              columns={columns && columns.length > 0 ? [...columns, operationObj] : []}
              dataSource={this.state.outPatData}
              pagination={false}
              rowKey={record => record.key}
              onRow={this.onClickRow}
              rowClassName={this.setRowClassNames}
              title={() => {
                return <div style={{ position: "relative" }}>
                  <p>
                    {visibleCard ? <span className="hide-card" onClick={this.handleHideLeftCard}>
                      <Tooltip title="隐藏查询条件">
                        <Icon type='double-left' style={{ fontSize: '18px' }} />
                      </Tooltip>
                    </span> : ""}
                    <span style={{ marginLeft: "4px" }}>已为您查询到</span>
                    {<span style={{ fontSize: '16px', margin: '0 5px', color: '#007AFF' }}>{this.state.total}</span>}
                    条记录
                    <span style={{ marginLeft: "8px" }}>{this.state.locName && this.state.locName ? this.state.locName : ""}</span>
                    <Divider type="vertical" />
                    <span>{this.state.docName && this.state.docName ? this.state.docName : ""}</span>
                    <Divider type="vertical" />
                    <span>
                      {dateFrom && dateFrom ? dateFrom : ""}
                      <span style={{ margin: "0 8px" }}>-</span>
                      {dateTo && dateTo ? dateTo : ""}
                    </span>
                  </p>

                </div>
              }}
              bordered
            />
            <CommonPagination size={this.state.size} current={this.state.page} pageSize={this.state.pageSize} total={this.state.total} search={this.state.search}
              onShowSizeChange={this.onShowSizeChange.bind(this)} complete={true} dataSource={this.state.outPatData}
              onChange={this.onChange.bind(this)} />
            <ColumnAuthoritysModel
              clientWidth='800px'
              compontName='OutPatientLog'
              configType="C"
              onRef={this.onColumnRef}
              reloadData={this.getMainTableColumns}
            />
            <RecordCompoent
              onRef={this.onConsumeSomeRef}
            ></RecordCompoent>
          </Card>

          {/* 查看病历 */}
          {emrVisible ? <ShowMedicalRecordModal
            admTypeCode="O"
            prCont="N"
            initTemplate="N"
            modalTitle="查看病历"
            isOperable={false}
            isBasicOperation="hidden"
            isShow={emrVisible}
            historyAdmID={emrAdmID}
            onHide={() => this.modifyEMRModal(false, {}, {})}
          /> : ''}
        </div>
      )
    }
  });

export default OutPaitentLog;